var sellerCode="";
$(document).ready(function() {
	//top.UppTabs.operator = top.getCurrentTagTitle();// 设置用户tab的标题值

	
	$( "#sellers" ).autocomplete({
		source: function( request, response ) {
	        $.ajax({
		          url: contextPath + '/iccard/report/getSellers',
		          dataType: "json",
		          data: {
		            maxRows: 10,
		            keyword: request.term
		          },
		          success: function( data ) {
		        	sellerCode="";
		            response( $.map( data, function( item ) {
		              return {
		                label: item.value+','+item.label,
		                value: item.label
		              };
		            }));
		          }
		        });
	      },
	      minLength: 2,
	      select: function( event, ui ) {
		        sellerCode=ui.item.label;
	      },
	      open: function() {
	        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
	      },
	      close: function() {
	        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
	      }
	    });
	    
});

function doSearch(){
	$("#data_list").datagrid({
		onLoadError : function() {
			uppAjaxError(data);
		},
		onLoadSuccess:function(data){
			$("#export_link").attr('href',contextPath+'/iccard/report/temp/'+data.fileName);
		},
		queryParams : {
			sellerCode : sellerCode
		},
		columns : [ [ {
			field : 'totalEarningsId',
			title : '',
			hidden : true
		}, {
			field : 'merchantName',
			title : '商家名称'
		}, {
			field : 'rechargeableCardExpenseAmount',
			title : '销售总额'
		}, {
			field : 'rechargeableCardHandleAmount',
			title : '应付总额'
		}, {
			field : 'rechargeableCardExpectedEarnings',
			title : '预期收益总额'
		}, {
			field : 'merchantCode',
			title : '操作',
			formatter : function(value, row, index) {
				return "<input type=\"button\" value=\"查看明细\" onclick=\"showDetail("+row.merchantCode+",'"+row.merchantName+"');\" />";
			}
		} ] ],
		autoRowHeight : true,
		fitColumns : true,
		pagination : true,
		nowrap : false,
		singleSelect : true,
		rownumbers : true
	});
	//汇总
	$.ajax({
        url: contextPath + '/iccard/report/bznis/prepaid/reportSum',
        dataType: "json",
        data: {
			packageId : sellerCode
		},
        success: function( data ) {
        	$("#collect_amount").text("销售总额 ："+data.salesTotal+"元         应付总额："+data.paidTotal+"元     预期收益总额 ： "+data.expectedTotal+"元");
        }
      });
}

function showDetail(id,name){
	var _title = "充值卡结算收益明细";
	var _href = contextPath
			+ "/iccard/report/bznis/prepaid/detail.jsp?sellerCode=" + id
			+ "&sellerName=" + name;
	parent.addTab(_title,_href);
}

